3 use Wikimedia\TestingAccessWrapper
;
10 * @covers SpecialWatchlist
12 class SpecialWatchlistTest
extends SpecialPageTestBase
{
13 public function setUp() {
16 $this->setTemporaryHook(
17 'ChangesListSpecialPageFilters',
21 $this->setTemporaryHook(
22 'ChangesListSpecialPageQuery',
27 'wgDefaultUserOptions',
29 'extendwatchlist' => 1,
30 'watchlistdays' => 3.0,
31 'watchlisthideanons' => 0,
32 'watchlisthidebots' => 0,
33 'watchlisthideliu' => 0,
34 'watchlisthideminor' => 0,
35 'watchlisthideown' => 0,
36 'watchlisthidepatrolled' => 0,
37 'watchlisthidecategorization' => 1,
38 'watchlistreloadautomatically' => 0,
39 'watchlistunwatchlinks' => 0,
45 * Returns a new instance of the special page under test.
49 protected function newSpecialPage() {
50 return new SpecialWatchlist();
53 public function testNotLoggedIn_throwsException() {
54 $this->setExpectedException( UserNotLoggedIn
::class );
55 $this->executeSpecialPage();
58 public function testUserWithNoWatchedItems_displaysNoWatchlistMessage() {
59 $user = new TestUser( __METHOD__
);
60 list( $html, ) = $this->executeSpecialPage( '', null, 'qqx', $user->getUser() );
61 $this->assertContains( '(nowatchlist)', $html );
65 * @dataProvider provideFetchOptionsFromRequest
67 public function testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams ) {
68 $page = TestingAccessWrapper
::newFromObject(
69 $this->newSpecialPage()
72 $context = new DerivativeContext( $page->getContext() );
74 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
75 $user = $this->getTestUser()->getUser();
77 foreach ( $preferences as $key => $value ) {
78 $user->setOption( $key, $value );
81 $context->setRequest( $fauxRequest );
82 $context->setUser( $user );
83 $page->setContext( $context );
85 $page->registerFilters();
86 $formOptions = $page->getDefaultOptions();
87 $page->fetchOptionsFromRequest( $formOptions );
89 $this->assertArrayEquals(
91 $formOptions->getAllValues(),
92 /* $ordered= */ false,
97 public function provideFetchOptionsFromRequest() {
98 // $defaults and $allFalse are just to make the expected values below
99 // shorter by hiding the background.
101 $page = TestingAccessWrapper
::newFromObject(
102 $this->newSpecialPage()
105 $this->setTemporaryHook(
106 'ChangesListSpecialPageFilters',
110 $page->registerFilters();
112 // Does not consider $preferences, just wiki's defaults
113 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
115 $allFalse = $wikiDefaults;
117 foreach ( $allFalse as $key => &$value ) {
118 if ( $value === true ) {
123 // This is not exposed on the form (only in preferences) so it
124 // respects the preference.
125 $allFalse['extended'] = true;
140 // First two same as prefs
144 // Second two overriden
145 'hideanons' => false,
147 'userExpLevel' => 'registered'
150 'watchlisthideminor' => 1,
151 'watchlisthidebots' => 0,
153 'watchlisthideanons' => 1,
154 'watchlisthideliu' => 0,
162 // Defaults/preferences for form elements are entirely ignored for
163 // action=submit and omitted elements become false
166 'hideminor' => false,
168 'hideanons' => false,
170 'userExpLevel' => 'unregistered'
173 'watchlisthideminor' => 0,
174 'watchlisthidebots' => 1,
176 'watchlisthideanons' => 0,
177 'watchlisthideliu' => 1,
182 'action' => 'submit',